﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.Rendering;

partial class CameraRenderer {
    partial void DrawGizmos();
    partial void DrawUnsupportedShaders();
    partial void PreparForSceneWindow();
    partial void PrepareBuffer();

#if UNITY_EDITOR
    static ShaderTagId[] legacyShaderTagIds = {
        new ShaderTagId("Always"),
        new ShaderTagId("ForwardBase"),
        new ShaderTagId("PrepassBase"),
        new ShaderTagId("Vertex"),
        new ShaderTagId("VertexLMRGBM"),
        new ShaderTagId("VertexLM")
    };
    static Material errorMaterial;

    string SampleName { get; set; }

    partial void DrawGizmos() {
        if (Handles.ShouldRenderGizmos()) {
            context.DrawGizmos(camera, GizmoSubset.PreImageEffects);
            context.DrawGizmos(camera, GizmoSubset.PostImageEffects);
        }
    }

    partial void DrawUnsupportedShaders() {
        if (null == errorMaterial) {
            errorMaterial = new Material(Shader.Find("Hidden/InternalErrorShader"));
        }
        var drawingSettings = new DrawingSettings(legacyShaderTagIds[0], new SortingSettings(camera)) {
            overrideMaterial = errorMaterial
        };
        var filteringSettings = FilteringSettings.defaultValue;

        for (int i = 1, iCount = legacyShaderTagIds.Length; i < iCount; i++) {
            drawingSettings.SetShaderPassName(i, legacyShaderTagIds[i]);
        }

        context.DrawRenderers(cullingResults, ref drawingSettings, ref filteringSettings);
    }

    partial void PreparForSceneWindow() {
        if (CameraType.SceneView == camera.cameraType) {
            ScriptableRenderContext.EmitWorldGeometryForSceneView(camera);
        }
    }

    partial void PrepareBuffer() {
        buffer.name = SampleName = camera.name;
    }
#else
    const string SampleName = bufferName;
#endif
}
